package com.cuit.job;

import lombok.SneakyThrows;
import org.reflections.Reflections;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

public class JobManager {
    private final List<Job> jobList;
    
    @SneakyThrows
    public JobManager(){
        jobList = new ArrayList<>();
        Reflections reflections = new Reflections();

        Set<Class<? extends Job>> classes = reflections.getSubTypesOf(Job.class);
        for (Class<? extends Job> clazz : classes){
            Job job = clazz.newInstance();
            jobList.add(job);
        }
        doJobs();
    }
    

    public void doJobs(){
        jobList.forEach(job -> {
            job.doJob();
        });
    }

}
